home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Xconq 7.0d37 / source / x11 / imf2x.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-18  |  2.6 KB  |  117 lines  |  [TEXT/KAHL]

  1. /* Convert the Xconq image format to X11 bitmaps and pixmaps.
  2.    Copyright (C) 1993, 1994 Stanley T. Shebs.
  3.  
  4. Xconq is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.  See the file COPYING.  */
  8.  
  9. #ifndef USE_CONSOLE
  10. #define USE_CONSOLE
  11. #endif
  12.  
  13. #include "config.h"
  14. #include "misc.h"
  15. #include "lisp.h"
  16. #include "imf.h"
  17. #include "xutil.h"
  18.  
  19. #include <X11/Xos.h>
  20. #include <X11/Xlib.h>
  21. #include <X11/Xutil.h>
  22. #include <X11/Xresource.h>
  23.  
  24. extern int numimages;
  25.  
  26. extern ImageFamily **images;
  27.  
  28. extern char *outdirname;
  29.  
  30. char imdirname[1000];
  31.  
  32. int showprogress = 0;
  33.  
  34. void usage PROTO ((void));
  35.  
  36. int
  37. main(argc, argv)
  38. int argc;
  39. char *argv[];
  40. {
  41.     int i;
  42.     char *arg;
  43.     FILE *ifp, *ofp;
  44.     Obj *form;
  45.     int startlineno = 0, endlineno = 0;
  46.  
  47.     init_lisp();
  48.  
  49.     if (argc == 1) usage();
  50.     for (i = 1; i < argc; ++i) {
  51.     arg = argv[i];
  52.     if (strcmp(arg, "-o") == 0) {
  53.         if (i + 1 < argc) {
  54.         outdirname = argv[i + 1];
  55.         /* Blast the arg because we'll be scanning the args again
  56.            and we want to ignore it then. */
  57.         argv[i] = NULL;
  58.         argv[i + 1] = NULL;
  59.         ++i;
  60.         } else {
  61.         init_error("No output directory following -o");
  62.         }
  63.     } else if (strcmp(arg, "-p") == 0) {
  64.         showprogress = 1;
  65.         argv[i] = NULL;
  66.     } else if (strcmp(arg, "--help") == 0) {
  67.         usage();
  68.         argv[i] = NULL;
  69.     }
  70.     }
  71.     /* We prefer a -o spec in order to do output, as a safety precaution;
  72.        one can always give "." as an argument so as to dump the bitmaps
  73.        into the current directory. */
  74.     if (outdirname == NULL)
  75.       init_warning("No output directory specified");
  76.     for (i = 1; i < argc; ++i) {
  77.     if (argv[i] != NULL) {
  78.         /* Interpret the arg as an imf file, open and read it. */
  79.         ifp = fopen(argv[i], "r");
  80.         if (ifp != NULL) {
  81.         while ((form = read_form(ifp, &startlineno, &endlineno))
  82.                != lispeof) {
  83.             interp_form_imfonly(form, NULL);
  84.         }
  85.         fclose(ifp);
  86.         } else {
  87.         run_warning("Couldn't open \"%s\", ignoring", argv[i]);
  88.         }
  89.     }
  90.     }
  91.     if (outdirname != NULL) {
  92.     /* Write the image directory file. */
  93.     sprintf(imdirname, "%s/%s", outdirname, "imf.dir");
  94.     ofp = fopen(imdirname, "w");
  95.     } else {
  96.     ofp = NULL;
  97.     }
  98.     for (i = 0; i < numimages; ++i) {
  99.     printf("/* %s imf */\n", images[i]->name);
  100.     if (ofp != NULL)
  101.       fprintf(ofp, "%s\n", images[i]->name);
  102.     write_x11_bitmaps(images[i], (ofp != NULL));
  103.     }
  104.     if (ofp != NULL) {
  105.     fclose(ofp);
  106.     }
  107.     return 0;
  108. }
  109.  
  110. void
  111. usage()
  112. {
  113.     fprintf(stderr,
  114.         "usage: imf2x [ files ... ] -o outdir [ files ... ] [ -p ]\n");
  115.     exit(1);
  116. }
  117.